package com.qs.sckill.service.impl;

import com.qs.sckill.entity.OrderInfo;
import com.qs.sckill.entity.User;
import com.qs.sckill.service.GoodsService;
import com.qs.sckill.service.OrderService;
import com.qs.sckill.service.SckillService;
import com.qs.sckill.vo.GoodsVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service(value = "sckillService")
public class SckillServiceImpl implements SckillService {

    @Resource
    private GoodsService goodsService;

    @Resource
    private OrderService orderService;

    @Override
    @Transactional
    public OrderInfo doSckill(User user, GoodsVo goods) {
        //减库存
        goodsService.reduceStock(goods);
        //下订单，写入秒杀订单
        return orderService.createOrder(user, goods);
    }
}
